﻿
// ProjectAADlg.cpp: 实现文件
//

#include "pch.h"
#include "framework.h"
#include "ProjectAA.h"
#include "ProjectAADlg.h"
#include "afxdialogex.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

//ImgCap *imgCap;
//ImgFile imgFile; 
//CTS CTSCam;

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

	// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CProjectAADlg 对话框



CProjectAADlg::CProjectAADlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PROJECTAA_DIALOG, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CProjectAADlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_100, Static1);
	DDX_Control(pDX, IDC_BUTTON_HOME4, Static2);
	DDX_Control(pDX, IDC_STATIC_101, Static3);
	DDX_Control(pDX, IDC_BUTTON1, Static4);
	DDX_Control(pDX, IDC_STATIC_60, Static5);
	DDX_Control(pDX, IDC_STATIC_66, Static6);
	DDX_Control(pDX, IDC_STATIC2, Static10);
	DDX_Control(pDX, IDC_STATIC_68, Static11);
	DDX_Control(pDX, IDC_STATIC3, Static12);
	DDX_Control(pDX, IDC_STATIC_96, Static13);
	DDX_Control(pDX, IDC_STATIC_2, Static14);
	DDX_Control(pDX, IDC_STATIC_1, Static15);
	DDX_Control(pDX, IDC_STATIC_51, Static16);
	DDX_Control(pDX, IDC_STATIC_10SN, Static17);
	DDX_Control(pDX, IDC_CHECK_10AUTO2, Button1);
	DDX_Control(pDX, IDC_CHECK_10AUTO, Button2);
	DDX_Control(pDX, IDC_BUTTON_HOME, Button3);
	DDX_Control(pDX, IDC_STATIC_10STATUS, Msg1);
	DDX_Control(pDX, IDC_STATIC_20STATUS2, Msg2);
	DDX_Control(pDX, IDC_STATIC_10ERROR, Msg3);
	DDX_Control(pDX, IDC_STATIC_20ERROR2, Msg4);
	DDX_Control(pDX, IDC_STATIC4, Static19);
	DDX_Control(pDX, IDC_STATIC5, Static20);
	DDX_Control(pDX, IDC_STATIC6, Static21);
	DDX_Control(pDX, IDC_STATIC_98, Static22);
	DDX_Control(pDX, IDC_STATIC_99, Static23);
	DDX_Control(pDX, IDC_STATIC_97, Static24);
	DDX_Control(pDX, IDC_STATIC7, Static25);
	DDX_Control(pDX, IDC_STATIC_69, Static26);
	DDX_Control(pDX, IDC_STATIC_53, Static27);
	DDX_Control(pDX, IDC_STATIC8, Static28);
	DDX_Control(pDX, IDC_STATIC_103, Static29);
	DDX_Control(pDX, IDC_STATIC_102, Static30);
	DDX_Control(pDX, IDC_STATIC_54, Static31);
	DDX_Control(pDX, IDC_STATIC_58, Static32);
	DDX_Control(pDX, IDC_CHECK_10AUTO3, Button4);
	DDX_Control(pDX, IDC_CHECK_10AUTO4, Button5);
	DDX_Control(pDX, IDC_STATIC_10STATUS2, Static33);
	DDX_Control(pDX, IDC_STATIC_10ERROR2, Static34);
	DDX_Control(pDX, IDC_STATIC_10STATUS3, Static35);
	DDX_Control(pDX, IDC_STATIC_10ERROR3, Static36);
	DDX_Control(pDX, IDC_STATIC_104, Static37);
	DDX_Control(pDX, IDC_BUTTON_START, m_butStart);
	DDX_Control(pDX, IDC_BUTTON_STOP, m_butStop);
	DDX_Control(pDX, IDC_BUTTON_SAVE, m_butSave);
}

BEGIN_MESSAGE_MAP(CProjectAADlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_32771, &CProjectAADlg::OnOpenLogDlg)
	ON_COMMAND(ID_32773, &CProjectAADlg::OnOpenMotorDlg)
	ON_WM_SIZE()
	ON_COMMAND(ID_32774, &CProjectAADlg::OnOpenTcpipDlg)
	ON_MESSAGE(WM_SEND_SOCKET_SERVER_MSG_TO_MAIN_UI, &CProjectAADlg::OnReceiveServerMsg)
	ON_WM_CTLCOLOR()
	ON_COMMAND(ID_32783, &CProjectAADlg::OnOpenProjectDlg)
	ON_COMMAND(ID_32784, &CProjectAADlg::OnOpenIODlg)
	ON_BN_CLICKED(IDC_BUTTON_HOME, &CProjectAADlg::OnBnClickedButtonHome)
	ON_BN_CLICKED(IDC_CHECK_10AUTO, &CProjectAADlg::OnBnClickedCheck10auto)
	ON_COMMAND(ID_32785, &CProjectAADlg::OnOpenControlDlg)
	ON_COMMAND(ID_32786, &CProjectAADlg::OnOpenSettingDlg)
	ON_COMMAND(ID_32787, &CProjectAADlg::OnOpenRS232Dlg)
	ON_BN_CLICKED(IDC_CHECK_10AUTO2, &CProjectAADlg::OnBnClickedCheck10auto2)
	ON_BN_CLICKED(IDC_BUTTON_HOME4, &CProjectAADlg::OnBnClickedButtonHome4)
	ON_BN_CLICKED(IDC_BUTTON1, &CProjectAADlg::OnBnClickedButton1)
	ON_COMMAND(ID_32788, &CProjectAADlg::OnOpenLoginDlg)
	ON_BN_CLICKED(IDC_CHECK_10AUTO4, &CProjectAADlg::OnBnClickedCheck10auto4)
	ON_BN_CLICKED(IDC_CHECK_10AUTO3, &CProjectAADlg::OnBnClickedCheck10auto3)
	ON_BN_CLICKED(IDC_BUTTON_START, &CProjectAADlg::OnBnClickedButtonStart)
	ON_BN_CLICKED(IDC_BUTTON_STOP, &CProjectAADlg::OnBnClickedButtonStop)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CProjectAADlg::OnBnClickedButtonSave)
	ON_COMMAND(ID_32789, &CProjectAADlg::OnOpenWhiteDlg)
	ON_BN_CLICKED(IDC_BUTTON2, &CProjectAADlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CProjectAADlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON_CCHECKSN, &CProjectAADlg::OnBnClickedButtonCchecksn)
	ON_BN_CLICKED(IDC_BUTTON_CCHECKSN2, &CProjectAADlg::OnBnClickedButtonCchecksn2)
END_MESSAGE_MAP()


// CProjectAADlg 消息处理程序

BOOL CProjectAADlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	unique_mutex = CreateMutex(NULL, FALSE, L"Youchuang10");
	DWORD errCode = GetLastError();
	if (errCode == ERROR_ALREADY_EXISTS) {
		Sleep(500);
		CloseHandle(unique_mutex);
		MessageBox(L"10站软件已经被打开!", L"Warning", 0);
		::TerminateProcess(::GetCurrentProcess(), NULL);//终止原先程序
	}

	// 设置字体参数
	gSystemMgr.m_editFont.CreateFont(28, 0, 4, 0, FW_NORMAL, FALSE, FALSE, 0,
		ANSI_CHARSET,
		OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY,
		DEFAULT_PITCH | FF_SWISS,
		_T("Arial"));
	Msg1.SetFont(&gSystemMgr.m_editFont);
	Msg2.SetFont(&gSystemMgr.m_editFont);
	Msg3.SetFont(&gSystemMgr.m_editFont);
	Msg4.SetFont(&gSystemMgr.m_editFont);
	Button1.SetFont(&gSystemMgr.m_editFont); //
	Button2.SetFont(&gSystemMgr.m_editFont); //
	Button3.SetFont(&gSystemMgr.m_editFont); //
	Static33.SetFont(&gSystemMgr.m_editFont); //
	Static34.SetFont(&gSystemMgr.m_editFont); //
	Static35.SetFont(&gSystemMgr.m_editFont); //
	Static36.SetFont(&gSystemMgr.m_editFont); //
	Button4.SetFont(&gSystemMgr.m_editFont); //
	Button5.SetFont(&gSystemMgr.m_editFont); //

	gSystemMgr.m_editFont2.CreateFontW(20, 0, 4, 0, 500, FALSE, FALSE, 0,
		ANSI_CHARSET,
		OUT_DEFAULT_PRECIS,
		CLIP_DEFAULT_PRECIS,
		DEFAULT_QUALITY,
		DEFAULT_PITCH | FF_SWISS,
		_T("Arial"));
	Static1.SetFont(&gSystemMgr.m_editFont2); //
	Static2.SetFont(&gSystemMgr.m_editFont2); //
	Static3.SetFont(&gSystemMgr.m_editFont2); //
	Static4.SetFont(&gSystemMgr.m_editFont2); //
	Static5.SetFont(&gSystemMgr.m_editFont2); //
	Static6.SetFont(&gSystemMgr.m_editFont2); //
	Static10.SetFont(&gSystemMgr.m_editFont2); //
	Static11.SetFont(&gSystemMgr.m_editFont2); //
	Static12.SetFont(&gSystemMgr.m_editFont2); //
	Static13.SetFont(&gSystemMgr.m_editFont2); //
	Static14.SetFont(&gSystemMgr.m_editFont2); //
	Static15.SetFont(&gSystemMgr.m_editFont2); //
	Static16.SetFont(&gSystemMgr.m_editFont2); //
	Static17.SetFont(&gSystemMgr.m_editFont2); //
	Static19.SetFont(&gSystemMgr.m_editFont2); //

	Static20.SetFont(&gSystemMgr.m_editFont2); //
	Static21.SetFont(&gSystemMgr.m_editFont2); //
	Static22.SetFont(&gSystemMgr.m_editFont2); //
	Static23.SetFont(&gSystemMgr.m_editFont2); //
	Static24.SetFont(&gSystemMgr.m_editFont2); //
	Static25.SetFont(&gSystemMgr.m_editFont2); //
	Static26.SetFont(&gSystemMgr.m_editFont2); //
	Static27.SetFont(&gSystemMgr.m_editFont2); //
	Static28.SetFont(&gSystemMgr.m_editFont2); //
	Static29.SetFont(&gSystemMgr.m_editFont2); //
	Static30.SetFont(&gSystemMgr.m_editFont2); //
	Static31.SetFont(&gSystemMgr.m_editFont2); //
	Static32.SetFont(&gSystemMgr.m_editFont2); //
	Static37.SetFont(&gSystemMgr.m_editFont2); //


	//轴的比率尺
	//gSystemMgr.m_vCMotor[MOTOR_Z].PositionRatio = 284.44;//3		102400/360

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	gSystemMgr.GeneralSettingIniInit();//读取型号配置

	m_menu.LoadMenuW(IDR_MENU1);
	this->SetMenu(&m_menu);

	//SetUiHandle();

	if (gSystemMgr.com_mutex != NULL)
		delete gSystemMgr.com_mutex;
	gSystemMgr.com_mutex = CreateMutex(NULL, FALSE, L"com_mutex");


	gSystemMgr.CaptureConfigIniInit();//采图配置
	gSystemMgr.TcpipConfigIniInit();//Tcpip通讯配置
	gSystemMgr.ReadErrorListIni();//错误信息
	gSystemMgr.PosConfigIniInit();//位置配置
	gSystemMgr.RS232ConfigIniInit();
	gSystemMgr.LoginConfigIniInit();
	gSystemMgr.MesConfigIniInit();

	gSystemMgr.m_ptrMainUI = this;

	if (m_cLogDlg == nullptr)
	{
		m_cLogDlg = new CLogDlg;
		m_cLogDlg->Create(IDD_DIALOG_LOG, this);
	}
	m_cLogDlg->ShowWindow(SW_HIDE);
	if (m_cControlDlg == nullptr)
	{
		m_cControlDlg = new CControlDlg;
		m_cControlDlg->Create(IDD_DIALOG_CONTROL, this);
	}
	m_cControlDlg->ShowWindow(SW_HIDE);

	bool bInit = gSystemMgr.MotorIO_Init();//轴卡初始化
	if (bInit)
	{
		gSystemMgr.StartGetMotorEncoderThread();
		//gSystemMgr.m_cIo.SetAllOutputOff();
		gSystemMgr.m_cIo.StartGetIoInputThread();
		gSystemMgr.m_cIo.SetOutputIo(35, ON);
		Sleep(1000);
		gSystemMgr.m_cIo.SetOutputIo(34, ON);
		gSystemMgr.m_cIo.SetOutputIo(36, ON);

		gSystemMgr.m_cIo.SetOutputIo(38, OFF);
		gSystemMgr.m_cIo.SetOutputIo(39, OFF);
	}

	switch (gSystemMgr.m_nImageSource)
	{
		case IMG_DEV_FILE:
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgFile;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"Image Files");
			break;
		case IMG_DEV_CTS:
			Cam_Init();
			gSystemMgr.m_bCTSInitFlag = 1;
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgCTS;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"CTS Cam");
			break;
		case IMG_RO_LONGO:
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgRLG;
			//SendMessage(HWND_STATUS, SB_SETTEXT, 2, (LPARAM)"RLG Cam");
			break;
		case IMG_CameraDS:
			gSystemMgr.imgCap = (ImgCap*)&gSystemMgr.imgCDS;
			break;
	}
	gSystemMgr.StartCaptureThread();
	gSystemMgr.StartImageTestThread();

	GetClientRect(&m_rcUiRect);

	//Tcpip通信自动建立服务器 或 自动连接
	if (gSystemMgr.m_nModeSelect == 0 && gSystemMgr.m_bAutoFlag) {
		USES_CONVERSION;
		char* c_strIp = T2A(gSystemMgr.m_cstrIPAdd);
		bool bCreateServer = gSystemMgr.m_cSocketServer.OpenSocketServer("Server", c_strIp, gSystemMgr.m_nPort);
		CString cstr;
		cstr.Format(L"Socket Server Build result:%d", bCreateServer);
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_ERROR);
		if (bCreateServer)
		{
			gSystemMgr.StartSocketAcceptClientThread();
		}

		//char* c_strIp2 = T2A(gSystemMgr.m_cstrIPAdd2);
		//bool bCreateServer2 = gSystemMgr.m_cSocketServer2.OpenSocketServer("Server2", c_strIp2, gSystemMgr.m_nPort2);
		//cstr.Format(L"Socket Server 2 Build result:%d", bCreateServer2);
		//gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_ERROR);
		//if (bCreateServer2)
		//{
		//	gSystemMgr.StartSocketAcceptClientThread2();
		//}
	}

	gSystemMgr.StartTcpipRelinkThread();
	gSystemMgr.StartScanButtonValueThread();
	gSystemMgr.StartOtherThread();
	gSystemMgr.StartAutoThread();
	gSystemMgr.StartLightControlThread();
	gSystemMgr.StartRS232LinkThread();

	//画按钮
	CRect rect;
	m_butStart.GetWindowRect(rect);
	long width = rect.right - rect.left;
	long height = rect.bottom - rect.top;
	HICON hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_START), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butStart.SetIcon(hicon_btn);
	m_butStop.GetWindowRect(rect);
	width = rect.right - rect.left;
	height = rect.bottom - rect.top;
	hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_STOP), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butStop.SetIcon(hicon_btn);
	m_butSave.GetWindowRect(rect);
	width = rect.right - rect.left;
	height = rect.bottom - rect.top;
	hicon_btn = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_SAVE), IMAGE_ICON, width - 30, height - 10, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION);
	m_butSave.SetIcon(hicon_btn);

	//更新显示
	int m_nCrtScreenWidth = 0;
	int m_nCrtScreenHeight = 0;
	CRect rcScreen;
	SystemParametersInfo(SPI_GETWORKAREA, 0, &rcScreen, 0);
	m_nCrtScreenWidth = rcScreen.Width() / 1;
	m_nCrtScreenHeight = rcScreen.Height() / 1;
	::SetWindowPos(m_hWnd, HWND_TOP, m_nCrtScreenWidth * 0, m_nCrtScreenHeight * 0, m_nCrtScreenWidth, m_nCrtScreenHeight, SWP_SHOWWINDOW);

	if (!gSystemMgr.changeImg.init_lib())
	{
		gSystemLog.DisplayLogAndSave(L"convert init error", LV_ERROR);
	}
	ShowWindow(SW_SHOWMAXIMIZED);
	SetWindowText(L"STK L4 S10 上料v3.2.6 [#Plasma]");
	return TRUE;
}

void CProjectAADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

void CProjectAADlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CRect rect;
		CPaintDC dc(this);
		GetClientRect(rect);
		dc.FillSolidRect(rect, RGB(169, 179, 195));//设置为绿色背景  

		CDialogEx::OnPaint();
	}
}

HCURSOR CProjectAADlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}


void CProjectAADlg::SetUiHandle()
{
	m_menu.EnableMenuItem(ID_32787, MF_DISABLED);
	m_menu.EnableMenuItem(ID_32774, MF_DISABLED);
	m_menu.EnableMenuItem(ID_32786, MF_DISABLED);
	m_menu.EnableMenuItem(ID_32789, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32784, MF_DISABLED);
	//m_menu.EnableMenuItem(ID_32785, MF_DISABLED);

}


void CProjectAADlg::OnOpenLogDlg()
{
	if (m_cLogDlg != nullptr)
	{
		m_cLogDlg->ShowWindow(SW_SHOW);
	}
}


void CProjectAADlg::OnOpenMotorDlg()
{
	if (m_cMotorDlg != nullptr)
	{
		delete m_cMotorDlg;
		m_cMotorDlg = nullptr;
	}
	if (m_cMotorDlg == nullptr)
	{
		m_cMotorDlg = new CMotorDlg;
		m_cMotorDlg->Create(IDD_DIALOG_MOTOR, this);
	}
	m_cMotorDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::Repaint(CWnd* pWnd, int last_Width, int now_Width, int last_Height, int now_Height, int cnt)
{
	if (pWnd)
	{
		CRect rect;
		CRect rect2;
		pWnd->GetWindowRect(&rect2);
		rect = OriRect[cnt];
		int n = 62;
		int m = 8;
		//rect2.top = rect2.top - n;
		//rect2.bottom = rect2.bottom - n;
		ScreenToClient(&rect2);

		double proportion_x = now_Width / (double)last_Width;
		double proportion_y = now_Height / (double)last_Height;

		rect.left = (long)(rect.left * proportion_x + 0.5 - m * proportion_x);
		rect.right = (long)(rect.left + RectW[cnt] * proportion_x + 0.5);
		rect.top = (long)(rect.top * proportion_y + 0.5 - n * proportion_y);
		rect.bottom = (long)(rect.top + RectH[cnt] * proportion_y + 0.5);
		pWnd->MoveWindow(&rect);
	}

}

void CProjectAADlg::OnSize(UINT nType, int cx, int cy)
{
	CDialogEx::OnSize(nType, cx, cy);

	if (nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED)//窗体大小发生变动。处理程序
	{
		float fsp[2];
		POINT Newp; //获取现在对话框的大小
		CRect recta;
		GetClientRect(&recta); //取客户区大小   
		Newp.x = recta.right - recta.left;
		Newp.y = recta.bottom - recta.top;
		fsp[0] = (float)Newp.x / Old.x;
		fsp[1] = (float)Newp.y / Old.y;
		CRect Rect;
		int woc;
		CPoint OldTLPoint, TLPoint; //左上角
		CPoint OldBRPoint, BRPoint; //右下角
		HWND hwndChild = ::GetWindow(m_hWnd, GW_CHILD); //列出所有控件   
		while (hwndChild)
		{
			woc = ::GetDlgCtrlID(hwndChild);//取得ID
			GetDlgItem(woc)->GetWindowRect(Rect);
			ScreenToClient(Rect);
			OldTLPoint = Rect.TopLeft();
			TLPoint.x = long(OldTLPoint.x * fsp[0]);
			TLPoint.y = long(OldTLPoint.y * fsp[1]);
			OldBRPoint = Rect.BottomRight();
			BRPoint.x = long(OldBRPoint.x * fsp[0]);
			BRPoint.y = long(OldBRPoint.y * fsp[1]); //高度不可读的控件（如:combBox),不要改变此值.
			Rect.SetRect(TLPoint, BRPoint);
			GetDlgItem(woc)->MoveWindow(Rect, TRUE);
			hwndChild = ::GetWindow(hwndChild, GW_HWNDNEXT);
		}
		Old = Newp;
	}
	//GetClientRect(&m_rcUiRect); //save size of dialog
	Invalidate();//更新窗口
}


void CProjectAADlg::OnOpenTcpipDlg()
{
	if (m_cTcpipDlg != nullptr)
	{
		delete m_cTcpipDlg;
		m_cTcpipDlg = nullptr;
	}
	if (m_cTcpipDlg == nullptr)
	{
		m_cTcpipDlg = new CTcpipDlg;
		m_cTcpipDlg->Create(IDD_DIALOG_TCPIP, this);
	}
	m_cTcpipDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnCancel()
{
	gSystemLog.DisplayLogAndSave(L"关闭软件", LV_ERROR);
	gSystemMgr.m_nExitFlag = 1;
	gSystemMgr.m_cIo.SetOutputIo(38, OFF);
	gSystemMgr.m_cIo.SetOutputIo(39, OFF);
	//delete m_cMotorDlg;
	//delete m_cLogDlg;
	//delete m_cProjectDlg;
	dmc_emg_stop(gSystemMgr.m_nCard);
	//gSystemMgr.m_vCMotor[MOTOR_Z1].ServoOff();
	Sleep(500);
	gSystemMgr.m_cRfidComm1.com_close();
	gSystemMgr.m_cRfidComm2.com_close();
	gSystemMgr.m_cRfidComm3.com_close();
	gSystemMgr.m_cRfidComm4.com_close();
	gSystemMgr.m_cScalesComm.com_close();

	dmc_board_close();//释放资源
	gSystemMgr.m_cClientGlue.CloseClient();
	gSystemMgr.m_cClientFangdai.CloseClient();

	CloseHandle(gSystemMgr.ProcAuto_20.ThreadProc);

	::TerminateProcess(::GetCurrentProcess(), NULL);

	CDialogEx::OnCancel();
}

LRESULT CProjectAADlg::OnReceiveServerMsg(WPARAM wParam, LPARAM lParam)
{
	CString cstrp = (BSTR)wParam;
	SysFreeString((BSTR)wParam);

	gSystemLog.DisplayLogAndSave(cstrp.GetBuffer(), LV_EVENT);

	std::vector<wstring> vResultItem = _utils::SplitString(cstrp.GetBuffer(), L",");

	if (vResultItem.size() < 2)
	{
		gSystemLog.DisplayLogAndSave(L"Client 返回的数据有误", LV_ERROR);
		return LRESULT();
	}

	return LRESULT();
}
HBRUSH CProjectAADlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr1 = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	DeleteObject(hbr);

	UINT id = pWnd->GetDlgCtrlID();
	CString Cstr;
	if (id == IDC_CHECK_10AUTO)
	{
		if (gSystemMgr.m_bAutoFlag_21) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_110)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"OK")
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else if (Cstr == L"NG")
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_62 || id == IDC_STATIC_64)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"...")
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		else
		{
			double val = _ttof(Cstr);
			if (val < gSystemMgr.glueWidthUp && val > gSystemMgr.glueWidthLow)
			{
				hbr = CreateSolidBrush(RGB(0, 255, 0));
			}
			else
			{
				hbr = CreateSolidBrush(RGB(255, 0, 0));
			}
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_CHECK_10AUTO2)
	{
		if (gSystemMgr.m_bAutoFlag_10) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_CHECK_10AUTO3)
	{
		if (gSystemMgr.m_bAutoFlag_20) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_CHECK_10AUTO4)
	{
		if (gSystemMgr.m_bAutoFlag_22) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetTextColor(RGB(0, 255, 0));
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetTextColor(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_60)
	{
		if (gSystemMgr.m_bHomeFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_66)
	{
		if (!gSystemMgr.m_bMotorErrorFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_100)
	{
		if (gSystemMgr.m_nPassRfidFlag) {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	//rfid
	else if (id == IDC_STATIC_97)
	{
		if (gSystemMgr./*m_cClient_W.m_bConnect*/ScalesConnectFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_108)
	{
		if (gSystemMgr.m_cClientWhite.m_bConnect)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_68)
	{
		if (gSystemMgr.Com1ConnectFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_96)
	{
		if (gSystemMgr.Com3ConnectFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC22) {
		if (gSystemMgr.PlasmaConnectFlag)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_109)
	{
		if (gSystemMgr.PlasmaCheckFlag == 1) //未屏蔽
		{
			if (gSystemMgr.PlasmaPowFlag == 1)
			{
				hbr = CreateSolidBrush(RGB(0, 255, 0));//正常
			}
			else
			{
				hbr = CreateSolidBrush(RGB(255, 0, 0));
			}
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_69)
	{
		if (gSystemMgr.Com2ConnectFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_102)
	{
		if (gSystemMgr.Com4ConnectFlag) {
			hbr = CreateSolidBrush(RGB(0, 255, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		else {
			hbr = CreateSolidBrush(RGB(255, 0, 0));
			pDC->SetBkMode(TRANSPARENT);
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_103)
	{
		if (gSystemMgr.m_cClientGlue.m_bConnect)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_104)
	{
		if (gSystemMgr.m_cClientFangdai.m_bConnect)
		{
			hbr = CreateSolidBrush(RGB(0, 255, 0));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_10STATUS || id == IDC_STATIC_10STATUS2 || id == IDC_STATIC_10STATUS3 || id == IDC_STATIC_20STATUS2)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"Testing")
		{
			hbr = CreateSolidBrush(RGB(222, 233, 20));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(70, 111, 166));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else if (id == IDC_STATIC_10ERROR || id == IDC_STATIC_10ERROR2 || id == IDC_STATIC_10ERROR3 || id == IDC_STATIC_20ERROR2)
	{
		GetDlgItem(id)->GetWindowTextW(Cstr);
		if (Cstr == L"...")
		{
			hbr = CreateSolidBrush(RGB(157, 187, 210));
		}
		else
		{
			hbr = CreateSolidBrush(RGB(255, 0, 0));
		}
		pDC->SetBkMode(TRANSPARENT);
	}
	else
	{
		hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	}
	hbr1 = hbr;
	return hbr1;
}


void CProjectAADlg::OnOpenProjectDlg()
{
	if (m_cProjectDlg != nullptr)
	{
		delete m_cProjectDlg;
		m_cProjectDlg = nullptr;
	}
	if (m_cProjectDlg == nullptr)
	{
		m_cProjectDlg = new CChangeProjectDlg;
		m_cProjectDlg->Create(IDD_DIALOG_PROJECT, this);
	}
	m_cProjectDlg->ShowWindow(SW_SHOW);
}



void CProjectAADlg::OnOpenIODlg()
{
	if (m_cIODlg != nullptr)
	{
		delete m_cIODlg;
		m_cIODlg = nullptr;
	}
	if (m_cIODlg == nullptr)
	{
		m_cIODlg = new CIODlg;
		m_cIODlg->Create(IDD_DIALOG_IO, this);
	}
	m_cIODlg->ShowWindow(SW_SHOW);
}

//#include <stdio.h>
unsigned int crc32_table[256];
void create_crc32_table() {
	unsigned int crc, i, j;
	for (i = 0; i < 256; i++) {
		crc = i;
		for (j = 0; j < 8; j++) {
			if (crc & 1) {
				crc = (crc >> 1) ^ 0xEDB88320;
			}
			else {
				crc = crc >> 1;
			}
		}
		crc32_table[i] = crc;
	}
}
unsigned int calculate_crc32(unsigned char* data, int length) {
	unsigned int crc = 0xFFFFFFFF;
	int i;
	for (i = 0; i < length; i++) {
		crc = (crc >> 8) ^ crc32_table[(crc & 0xFF) ^ data[i]];
		return crc ^ 0xFFFFFFFF;
	}
}

static const uint32_t crc32tab[] = {
 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL,
 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
 0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L,
 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
 0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL,
 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L,
 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L,
 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
 0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L,
 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
 0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL,
 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L,
 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL,
 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
 0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL,
 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
 0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L,
 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
 0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L,
 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L,
 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
 0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL,
 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
 0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL,
 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL,
 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L,
 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
 0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L,
 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
 0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L,
 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL,
 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L,
 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
 0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL,
 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
 0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L,
 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L,
 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L,
 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
 0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L,
 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
};
uint32_t crc32(const unsigned char* buf, uint32_t size)
{
	uint32_t i, crc;
	crc = 0xFFFFFFFF;
	for (i = 0; i < size; i++)
		crc = crc32tab[(crc ^ buf[i]) & 0xff] ^ (crc >> 8);
	return crc ^ 0xFFFFFFFF;
}

static uint32_t crc32_2(uint8_t* buf, int len)
{
	int i, j;
	uint32_t crc, mask;

	crc = 0xFFFFFFFF;
	for (i = 0; i < len; i++) {
		crc = crc ^ (uint32_t)buf[i];
		for (j = 7; j >= 0; j--) {    // Do eight times.
			mask = (crc & 1);
			crc = (crc >> 1) ^ (0xEDB88320 & mask);
		}
	}
	return ~crc;
}

unsigned int crc32table[256];
void genCRC32table()
{
	int i;
	int j;
	unsigned int crc;
	for (i = 0; i < 256; i++) {
		crc = i;
		for (j = 0; j < 8; j++) {
			if ((crc & 1) == 1)
				//crc = (crc >> 1) ^ 0xEDB88320;
				crc = (crc >> 1) ^ 0x04C11DB7;
			else
				crc >>= 1;
		}
		crc32table[i] = crc;
	}
}
//0x84, 0x0330, 0x00, 0x1608
//0x84, 0x0331, 0x30, 0x1608
//0x84, 0x0318, 0x5E, 0x1608
//0x84, 0x0002, 0x43, 0x1608
//
//0x00, 0x0000, 0xff, 0x1608
//0x90, 0x0010, 0x21, 0x1608
//0x00, 0x0000, 0xff, 0x1608
//0x84, 0xa092, 0x92, 0x1608
//0x84, 0xa090, 0x90, 0x1608
//0x84, 0xa094, 0x94, 0x1608
//
//0x00, 0x0000, 0xff, 0x1608
//0x90, 0x0010, 0x21, 0x1608
//0x00, 0x0000, 0xff, 0x1608
//0x84, 0x008b, 0x31, 0x1608
//0x84, 0x0044, 0x22, 0x1608
//0x84, 0x0045, 0x20, 0x1608
//0x84, 0x0331, 0x33, 0x1608
//0x84, 0x005b, 0x00, 0x1608
//0x84, 0x0330, 0x00, 0x1608
//0x84, 0x0332, 0xe0, 0x1608
//0x00, 0x0000, 0x20, 0x1608
//0x00, 0x0000, 0x50, 0x1608
//0x90, 0x0330, 0x04, 0x1608
//0x90, 0x0050, 0x00, 0x1608
//0x90, 0x0051, 0x01, 0x1608
//0x90, 0x0052, 0x02, 0x1608
//0x90, 0x0053, 0x03, 0x1608
//0x90, 0x0320, 0x2a, 0x1608
//0x90, 0x0323, 0x2a, 0x1608
//0x90, 0x040b, 0x07, 0x1608
//0x90, 0x042d, 0x15, 0x1608
//0x90, 0x040d, 0x1e, 0x1608
//0x90, 0x040e, 0x1e, 0x1608
//0x90, 0x040f, 0x00, 0x1608
//0x90, 0x0410, 0x00, 0x1608
//0x90, 0x0411, 0x01, 0x1608
//0x90, 0x0412, 0x01, 0x1608
//0x90, 0x044b, 0x07, 0x1608
//0x90, 0x046d, 0x15, 0x1608
//0x90, 0x044d, 0x1e, 0x1608
//0x90, 0x044e, 0x5e, 0x1608
//0x90, 0x044f, 0x00, 0x1608
//0x90, 0x0450, 0x40, 0x1608
//0x90, 0x0451, 0x01, 0x1608
//0x90, 0x0452, 0x41, 0x1608
//0x90, 0x0333, 0x1b, 0x1608
//0x90, 0x0313, 0x02, 0x1608
//0x00, 0x0000, 0x20, 0x1608
//0x84, 0x02be, 0x80, 0x1608
//0x84, 0x0318, 0x5e, 0x1608
//0x84, 0x0383, 0x00, 0x1608
//0x00, 0x0000, 0x64, 0x1608
//0x84, 0x02bf, 0x60, 0x1608
//0x84, 0x02be, 0x90, 0x1608
//0x00, 0x0000, 0x64, 0x1608
//0x00, 0x0000, 0xff, 0x1608
//0x90, 0x0010, 0x21, 0x1608
//0x00, 0x0000, 0xff, 0x1608

unsigned int crc32_3(const unsigned char* buf, uint32_t size)
{
	genCRC32table();

	uint32_t i, crc;
	crc = 0xFFFFFFFF;
	for (i = 0; i < size; i++)
		crc = (crc >> 8) ^ crc32table[(crc ^ buf[i]) & 0xFF];
	//crc = (crc >> 8) ^ crc32table[(crc & 0xFF) ^ buf[i]];
	return crc ^ 0xFFFFFFFF;
	//return crc ^ ~0U;
}

unsigned int crcTable[256];
void GenerateTable(uint32_t polynomial)
{
	for (int byte = 0; byte < 256; ++byte)
	{
		uint32_t crc = byte;

		for (int bit = 32; bit > 0; --bit)
		{
			if (crc & 0x80000000)
			{
				crc = (crc << 1) ^ polynomial;
			}
			else
			{
				crc <<= 1;
			}
		}
		crcTable[byte] = crc;
	}
}
unsigned int calcMsgCRC(BYTE* msg, unsigned int len)
{
	GenerateTable(0xEDB88320);//0x04C11DB7
	unsigned long crc = 0;
	for (int n = 0; n < len; n++)
	{
		uint8_t c = msg[n] & 0xff;
		crc = crcTable[(crc >> 24) ^ c] ^ (crc << 8);
	}
	return crc;
}


uint32_t calculateEthernetCRC32(BYTE* bytes, unsigned int length) {
	uint32_t crc = 0xFFFFFFFF; // 初始化CRC32值为0xFFFFFFFF

	for (size_t i = 0; i < length; ++i) {
		crc ^= bytes[i]; // 异或操作

		for (int j = 0; j < 8; ++j) {
			if (crc & 1) {
				//crc = (crc >> 1) ^ 0xEDB88320; // 右移1位并进行异或操作
				crc = (crc >> 1) ^ 0x04C11DB7; // 右移1位并进行异或操作
			}
			else {
				crc >>= 1; // 右移1位
			}
		}
	}

	crc ^= 0xFFFFFFFF; // 最后取反

	return crc;
}



//f8 c9 b7 a4 4f 41 42 44 01 00 00 00 08 00 00 00 00 00 00 00 00 03 00 00 aa 55 55 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
//00 00 00 00 00 00

void CProjectAADlg::OnBnClickedButtonHome()
{
	//	{
	//		BYTE Write_Sn[256] = {
	//0xf8,0xc9,0xb7 ,0xa4 ,0x4f ,0x41 ,0x42 ,0x44 ,0x01 ,0x00 ,0x00 ,0x00 ,0x08 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x03 ,0x00 ,0x00 ,0xaa ,0x55 ,0x55 ,0xaa ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
	//0x00,0x00,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
	//0x00,0x00,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
	//0x00,0x00,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
	//0x00,0x00,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
	//0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 };//写入条码
	//		BYTE CRC[2] = { 0 };
	//		crc32(Write_Sn, 256);
	//
	//		CString cstr;
	//		cstr.Format(L"%x", calculateEthernetCRC32(Write_Sn, 256));
	//		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	//	}

	gSystemLog.DisplayLogAndSave(L"按下回原点按钮", LV_EVENT);
	if (gSystemMgr.m_bHomeFlag == 0)
		gSystemMgr.m_nButtonValue = 10;
}


void CProjectAADlg::OnBnClickedCheck10auto()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_10AUTO);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		if (gSystemMgr.GlueSNCheckFlag == 1) {
			if (m_cGlueSNCheckDlg != nullptr)
			{
				delete m_cGlueSNCheckDlg;
				m_cGlueSNCheckDlg = nullptr;
			}
			if (m_cGlueSNCheckDlg == nullptr)
			{
				m_cGlueSNCheckDlg = new CGlueSNCheckDlg;
				m_cGlueSNCheckDlg->Create(IDD_DIALOG_GLUESNCHECK, this);
			}
			m_cGlueSNCheckDlg->ShowWindow(SW_SHOW);
		}
		else {
			gSystemMgr.m_bAutoFlag_21 = 1;
			gSystemMgr.m_cIo.SetOutputIo(27, OFF);
			gSystemMgr.m_cIo.SetOutputIo(30, ON);
			cstr.Append(L"点胶开启自动");
			gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
			GetDlgItem(IDC_CHECK_10AUTO)->SetWindowTextW(L"点胶");
		}
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoFlag_21 = 0;
		cstr.Append(L"点胶关闭自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO)->SetWindowTextW(L"点胶");
	}
}


void CProjectAADlg::OnOpenControlDlg()
{
	//if (m_cControlDlg != nullptr)
	//{
	//	delete m_cControlDlg;
	//	m_cControlDlg = nullptr;
	//}
	if (m_cControlDlg == nullptr)
	{
		m_cControlDlg = new CControlDlg;
		m_cControlDlg->Create(IDD_DIALOG_CONTROL, this);
	}
	m_cControlDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnOpenSettingDlg()
{
	if (m_cSettingDlg != nullptr)
	{
		delete m_cSettingDlg;
		m_cSettingDlg = nullptr;
	}
	if (m_cSettingDlg == nullptr)
	{
		m_cSettingDlg = new CSettingDlg;
		m_cSettingDlg->Create(IDD_DIALOG_SETTING, this);
	}
	m_cSettingDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnOpenRS232Dlg()
{
	if (m_cRS232Dlg != nullptr)
	{
		delete m_cRS232Dlg;
		m_cRS232Dlg = nullptr;
	}
	if (m_cRS232Dlg == nullptr)
	{
		m_cRS232Dlg = new CRS232Dlg;
		m_cRS232Dlg->Create(IDD_DIALOG_RS232, this);
	}
	m_cRS232Dlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedCheck10auto2()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_10AUTO2);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_bAutoFlag_10 = 1;

		//gSystemMgr.m_cIo.SetOutputIo(44, ON);//上线体电机
		gSystemMgr.m_cIo.SetOutputIo(37, ON);//下线体电机

		cstr.Append(L"上料开启自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO2)->SetWindowTextW(L"上料");
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoFlag_10 = 0;
		cstr.Append(L"上料关闭自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO2)->SetWindowTextW(L"上料");
	}
}



BOOL CProjectAADlg::PreTranslateMessage(MSG* pMsg)
{
	CString cstr;
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_SPACE) return TRUE; //如果是空格消息，返回；
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) return TRUE; //如果是Esc消息，返回；

	if (gSystemMgr.m_nGetCodeFlag == 0 && pMsg->message == WM_KEYDOWN) {
		USES_CONVERSION;
		if (pMsg->wParam == VK_RETURN && gSystemMgr.m_nBarcodeLength > 0)
		{
			gSystemLog.DisplayLogAndSave(A2T(gSystemMgr.Barcode), LV_EVENT);
			SetDlgItemTextW(IDC_STATIC_10SN, A2T(gSystemMgr.Barcode));
			//gSystemMgr.m_nGetCodeFlag = 1;
			if (gSystemMgr.CheckSNFlag == 1) {
				if (gSystemMgr.m_nBarcodeLength == gSystemMgr.CheckSNLength) {
					gSystemMgr.m_nGetCodeFlag = 1;
					gSystemLog.DisplayLogAndSave(L"扫码成功 - 1", LV_EVENT);
				}
				else {
					CString cstr;
					cstr.Format(L"PCB码长度错误:[%d],%s", gSystemMgr.m_nBarcodeLength, A2T(gSystemMgr.Barcode));
					gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);

					SetDlgItemTextW(IDC_STATIC_10SN, L"...");
					gSystemMgr.m_nGetCodeFlag = 0;
					memset(gSystemMgr.Barcode, 0, sizeof(gSystemMgr.Barcode));
					gSystemMgr.m_nBarcodeLength = 0;
				}
			}
			else {
				gSystemMgr.m_nGetCodeFlag = 1;
				gSystemLog.DisplayLogAndSave(L"扫码成功 - 2", LV_EVENT);
			}
			return true;
		}
		if (gSystemMgr.m_nBarcodeLength >= 50) {
			gSystemMgr.m_nGetCodeFlag = 0;
			memset(gSystemMgr.Barcode, 0, sizeof(gSystemMgr.Barcode));
			gSystemMgr.m_nBarcodeLength = 0;
			gSystemLog.DisplayLogAndSave(L"扫码长度异常", LV_EVENT);
			return true;
		}
		switch (pMsg->wParam)
		{
			case VK_A:
			case VK_B:
			case VK_C:
			case VK_D:
			case VK_E:
			case VK_F:
			case VK_G:
			case VK_H:
			case VK_I:
			case VK_J:
			case VK_K:
			case VK_L:
			case VK_M:
			case VK_N:
			case VK_O:
			case VK_P:
			case VK_Q:
			case VK_R:
			case VK_S:
			case VK_T:
			case VK_U:
			case VK_V:
			case VK_W:
			case VK_X:
			case VK_Y:
			case VK_Z:
			case VK_0:
			case VK_1:
			case VK_2:
			case VK_3:
			case VK_4:
			case VK_5:
			case VK_6:
			case VK_7:
			case VK_8:
			case VK_9:
				gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = pMsg->wParam;
				gSystemMgr.m_nBarcodeLength++;
				gSystemMgr.ShiftFlag = 0;
				break;
			case 16://shift
				gSystemMgr.ShiftFlag = 1;
				break;
			case 189:
				if (gSystemMgr.ShiftFlag == 1) {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '_';
					gSystemMgr.m_nBarcodeLength++;
				}
				else {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '-';
					gSystemMgr.m_nBarcodeLength++;
				}
				gSystemMgr.ShiftFlag = 0;
				break;
			case 191:
				if (gSystemMgr.ShiftFlag == 1) {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '?';
					gSystemMgr.m_nBarcodeLength++;
				}
				else {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '/';
					gSystemMgr.m_nBarcodeLength++;
				}
				gSystemMgr.ShiftFlag = 0;
				break;
			case 220:
				if (gSystemMgr.ShiftFlag == 1) {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '|';
					gSystemMgr.m_nBarcodeLength++;
				}
				else {
					gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = '\\';
					gSystemMgr.m_nBarcodeLength++;
				}
				gSystemMgr.ShiftFlag = 0;
				break;
			default:
				gSystemMgr.ShiftFlag = 0;
				cstr.Format(L"%d", int(pMsg->wParam));
				gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
				break;
		}
		//gSystemMgr.Barcode[gSystemMgr.m_nBarcodeLength] = pMsg->wParam;
		//gSystemMgr.m_nBarcodeLength++;
		if (gSystemMgr.m_nBarcodeLength > 0)
		{
			SetDlgItemTextW(IDC_STATIC_10SN, A2T(gSystemMgr.Barcode));
		}
	}

	if (pMsg->message == WM_KEYDOWN) return TRUE;//屏蔽所有键盘按键消息

	//if (pMsg->wParam == IDCANCEL && pMsg->message == WM_COMMAND/*273*/ && pMsg->hwnd == m_hWnd) {
	//	cstr.Format(L"关闭消息[%d]:%d - %d", gSystemMgr.CloseFlag, int(pMsg->wParam), int(pMsg->message));
	//	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	//}

	//if (pMsg->wParam == IDCANCEL && gSystemMgr.CloseFlag == 0 && pMsg->message == WM_COMMAND/*273*/ && pMsg->hwnd == m_hWnd) {
	//	cstr.Format(L"关闭消息[%d]:--------%d - %d", gSystemMgr.CloseFlag, int(pMsg->wParam), int(pMsg->message));
	//	gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
	//	return TRUE;
	//}

	return CDialogEx::PreTranslateMessage(pMsg);
}




void CProjectAADlg::OnBnClickedButtonHome4()
{
	if (gSystemMgr.m_nPassRfidFlag) {
		if (IDYES == AfxMessageBox(L"确定 开启RFID 吗？", MB_YESNO | MB_ICONWARNING))
		{
			gSystemMgr.m_nPassRfidFlag = 0;
		}
	}
	else {
		if (IDYES == AfxMessageBox(L"确定 屏蔽RFID 吗？", MB_YESNO | MB_ICONWARNING))
		{
			gSystemMgr.m_nPassRfidFlag = 1;
		}
	}
}


void CProjectAADlg::OnBnClickedButton1()
{
	gSystemLog.DisplayLogAndSave(L"手动清零条码", LV_EVENT);
	SetDlgItemTextW(IDC_STATIC_10SN, L"...");
	gSystemMgr.m_nGetCodeFlag = 0;
	memset(gSystemMgr.Barcode, 0, sizeof(gSystemMgr.Barcode));
	gSystemMgr.m_nBarcodeLength = 0;
}



void CProjectAADlg::OnOpenLoginDlg()
{
	if (m_cLoginDlg != nullptr)
	{
		m_cLoginDlg->ShowWindow(SW_SHOW);
	}
	if (m_cLoginDlg == nullptr)
	{
		m_cLoginDlg = new CLoginDlg;
		m_cLoginDlg->Create(IDD_DIALOG_LOGIN, this);
	}
	m_cLoginDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedCheck10auto4()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_10AUTO4);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_bAutoFlag_22 = 1;
		cstr.Append(L"检胶开启自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO4)->SetWindowTextW(L"检胶");
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoFlag_22 = 0;
		cstr.Append(L"检胶关闭自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO4)->SetWindowTextW(L"检胶");
	}
}


void CProjectAADlg::OnBnClickedCheck10auto3()
{
	CString cstr;
	CButton* pCheckBox = (CButton*)GetDlgItem(IDC_CHECK_10AUTO3);
	int nFlag = pCheckBox->GetCheck();
	if (nFlag == BST_CHECKED)
	{
		gSystemMgr.m_bAutoFlag_20 = 1;
		cstr.Append(L"Plasma开启自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO3)->SetWindowTextW(L"Plasma");
	}
	if (nFlag == BST_UNCHECKED)
	{
		gSystemMgr.m_bAutoFlag_20 = 0;
		cstr.Append(L"Plasma关闭自动");
		gSystemLog.DisplayLogAndSave(cstr.GetBuffer(), LV_EVENT);
		GetDlgItem(IDC_CHECK_10AUTO3)->SetWindowTextW(L"Plasma");
	}
}


void CProjectAADlg::OnBnClickedButtonStart()
{
	gSystemMgr.m_bStopCapture = 0;
	CWnd* pBtn = nullptr;
	pBtn = (CWnd*)GetDlgItem(IDC_BUTTON_START);
	pBtn->EnableWindow(FALSE);
}


void CProjectAADlg::OnBnClickedButtonStop()
{
	gSystemMgr.m_bStopCapture = 1;
	gSystemMgr.imgCap->m_bInitFlag = FALSE;
	CWnd* pBtn = nullptr;
	pBtn = (CWnd*)GetDlgItem(IDC_BUTTON_START);
	pBtn->EnableWindow(TRUE);
}


void CProjectAADlg::OnBnClickedButtonSave()
{
	gSystemMgr.SaveTestReport_White(gSystemMgr.imgCap->bBmpTestBuf, gSystemMgr.imgCap->iBmpW, gSystemMgr.imgCap->iBmpH, 0);
}


void CProjectAADlg::OnOpenWhiteDlg()
{
	if (m_cCaptureDlg != nullptr)
	{
		m_cCaptureDlg->ShowWindow(SW_SHOW);
	}
	if (m_cCaptureDlg == nullptr)
	{
		m_cCaptureDlg = new CCaptureDlg;
		m_cCaptureDlg->Create(IDD_DIALOG_CAPTURE, this);
	}
	m_cCaptureDlg->ShowWindow(SW_SHOW);
}


void CProjectAADlg::OnBnClickedButton2()
{
	gSystemMgr.CloseFlag = 1;
	gSystemLog.DisplayLogAndSave(L"关闭按钮按下", LV_EVENT);
}


void CProjectAADlg::OnBnClickedButton3()
{
	gSystemMgr.m_nButtonValue = 300;
}


void CProjectAADlg::OnBnClickedButtonCchecksn()
{
	CString sn(gSystemMgr.Barcode);
	USES_CONVERSION;
	bool v = gSystemMgr.MesCheckSN(T2A(sn), T2A(gSystemMgr.st10wp_code));

	if (v)
	{
		MessageBox(L"SNOK", L"校验SN");
	}
	else
	{
		MessageBox(L"SNNG", L"校验SN", MB_ICONERROR);
	}
}

void CProjectAADlg::OnBnClickedButtonCchecksn2()
{
	SetDlgItemTextW(IDC_STATIC_110, L"...");
	SetDlgItemTextW(IDC_STATIC_64, L"...");
	SetDlgItemTextW(IDC_STATIC_62, L"...");
	CString cstr;
	cstr.Format(L"Trigger");
	gSystemMgr.m_cClientGlue.m_sendBuffer.push_front(cstr.GetBuffer());
}
